<?php
/**
 * Created by PhpStorm.
 * User: Sky
 * Date: 2017/8/3
 * Time: 下午2:45
 */

namespace app\controllers;


use app\librarys\BaseController;
use app\models\User;
use yii\data\Pagination;

class UserController extends BaseController
{
    public function actionUserList()
    {
        $count = User::getCount();
        $pagination = new Pagination(['totalCount' => $count]);
        $items = User::getList($pagination->page, $pagination->pageSize);
        return $this->render('user-list',
            [
                'items' => $items,
                'pagination' => $pagination
            ]
        );
    }

    public function actionUserDetailPartial()
    {
        $id = \Yii::$app->request->post('id');
        $item = User::getById($id);
        return $this->renderPartial('user-detail-partial', ['item' => $item]);
    }

    /**
     * 提现
     */
    public function actionEnchashmentRecordList()
    {
        $count = User::getEnchashmentRecordCount();
        $pagination = new Pagination(['totalCount' => $count]);
        $items = User::getEnchashmentRecordList($pagination->page, $pagination->pageSize);
        return $this->render('enchashment-record-list',
            [
                'items' => $items,
                'pagination' => $pagination
            ]
        );
    }

    public function actionEnchashmentRecordDetailPartial()
    {
        $id = \Yii::$app->request->post('id');
        $item = User::getEnchashmentRecordDetail($id);
        return $this->renderPartial('enchashment-record-detail-partial', ['item' => $item]);
    }

    public function actionEnchashmentAuthSuccessHandler()
    {
        $authId = \Yii::$app->request->post('id');
        $authRemark = \Yii::$app->request->post('auth_remark');
        $result = User::enchashmentSuccess($authId, $authRemark);
        return $this->renderJson(null, $result);
    }

    public function actionEnchashmentAuthFailedHandler()
    {
        $authId = \Yii::$app->request->post('id');
        $authRemark = \Yii::$app->request->post('auth_remark');
        User::enchashmentFailed($authId, $authRemark);
        return $this->renderJson();
    }
}